<?php
/*
 * @Author: your name
 * @Date: 2021-10-20 14:55:40
 * @LastEditTime: 2021-10-22 11:26:58
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tp30\app\admin\model\Category.php
 */

namespace app\admin\model;

use think\Model;

class Category extends Model
{
    public function searchParentidAttr($q, $v, $d)
    {
        $q->where('parentid', '=', $v);
    }
    // protected $table = 'table_name';
    // protected $pk = 'id';
    public static function getCategoryList()
    {
        $list = Category::select()->toArray();
        return $list;
    }
    public static function getWhereList($where)
    {
        $list = Category::withSearch(array_keys($where), $where)
            ->order("sort")
            ->select()
            ->toArray();
        return $list;
    }
    public static function addCate($data)
    {
        try {
            $res = Category::create($data);
            $msg = '添加成功';
        } catch (\Exception $th) {
            $res = false;
            $msg = $th->getMessage();
        }
        return [$res, $msg];
    }
    public static function editCate($data)
    {
        try {
            $res = Category::update($data);
            $msg = '修改成功';
        } catch (\Exception $th) {
            $res = false;
            $msg = $th->getMessage();
        }
        return [$res, $msg];
    }
}
